
import {size, formItemLayout, widthFormItemLayout, getImages, getFileList } from '../../utils/common';
import React from 'react';
import { Modal, Form, Input, Select, InputNumber } from 'antd';
import * as api from '../../api/api';
import { FormComponentProps } from 'antd/lib/form';
export interface HomeSettingEditProps extends FormComponentProps {
    visible: boolean,
    homeSetting?: api.SingleUserMallStoreSettingsVOHomeSettingVO,
    onSave: (any) => void,
    onCancel: () => void,
}
class HomeSettingEdit extends React.PureComponent<HomeSettingEditProps, any>{
    constructor(props) {
        super(props);
    }

    state = {
        id: 0
    }

    componentDidMount() {
        const id = this.props.homeSetting && this.props.homeSetting.id;
        this.setState({id:id});
    }

    ok = (e) => {
        e.preventDefault();
        this.props.form.validateFieldsAndScroll((err, form) => {
            if (!err) {
                form['id'] = this.state.id;
                this.props.onSave(form);
            }
        });
    }

    cancel = () => {
        this.props.onCancel();
    }
    
    render(): JSX.Element {
        const { getFieldDecorator } = this.props.form;
        const { homeSetting } = this.props;
        return (
            <Modal
                title='首页设置'
                visible={this.props.visible}
                onOk={this.ok}
                onCancel={this.cancel}
                maskClosable={true}
                width={650}
            >
                <Form>
                    <Form.Item label="首页设置描述" {...formItemLayout}>
                        {getFieldDecorator('description', {
                            rules: [
                                {
                                    required: true,
                                    message: '请输入描述'
                                }
                            ],
                            initialValue: homeSetting && homeSetting.description
                        })(<Input size={size} 
                            placeholder="请输入描述" />)}
                    </Form.Item>
                    <Form.Item label="设置字体大小（单位rem 范围1~37 例如25）" {...widthFormItemLayout}>
                        {getFieldDecorator('fontSize', {
                            rules: [
                                {
                                    required: true,
                                    message: '请输入值'
                                }
                            ],
                            initialValue: homeSetting && homeSetting.fontSize
                        })(<InputNumber size={size} min={1} max={37}
                            placeholder="请输入值" />)}
                    </Form.Item>
                    <Form.Item label="设置字体颜色（以#开头 例如#000000 黑色）" {...widthFormItemLayout}>
                        {getFieldDecorator('color', {
                            rules: [
                                {
                                    required: true,
                                    message: '请输入颜色'
                                }
                            ],
                            initialValue: homeSetting && homeSetting.color
                        })(<Input size={size}
                            placeholder="请输入颜色" />)}
                    </Form.Item>
                </Form>
            </Modal>)
    }
}

export default Form.create()(HomeSettingEdit);